<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/12/012
 * Time: 10:34
 */

namespace app\admin\controller;


use think\Controller;
use think\Db;

class Json extends Controller
{

    /*623接口*/
    /*提交订单接口*/
    public function addOrder()//订单提交 
    {
        $data=[
          'train_id'=>input('train_id'),
          'activity_id'=>input('activity_id'),
          'game_id'=>input('game_id'),
            'user_id'=>input('user_id'),
        ];
        // dump($data);exit;
        $sql=Db::table('ordertype')
            ->insert($data);
        if ($sql) {
            return 'success:1';
        }else {
            return 'error';
        }
    }   
    /*http://localhost/YueJian/public/admin/json/addOrder?game_id=1&user_id=5*/

    /*提问大师问题接口*/
    public function subQuestion () {
        $data=[
          'user_id' => input('user_id'),
          'masterquestion_con' => input('content'),
          'master_id' => input('master_id')
        ];
        dump($data);
         $sql=Db::table('masterquestion')
            ->insert($data);
        if ($sql) {
            return 'success:1';
        }else {
            return 'error';
        }
    }
    /*http://localhost/YueJian/public/admin/json/subQuestion?user_id=6&content='哈哈’&master_id=1;*/

    /*大师回答接口*/
    public function anQuestion () {
        $id = input('masterquestion_id');
         $data=[
          'masterquestion_res' => input('content')
        ];
        // dump($data);
         $sql=Db::table('masterquestion')
            ->where('masterquestion_id',$id)
            ->update($data);
        if ($sql) {
            return 'success:1';
        }else {
            return 'error';
        }
    }
    /*http://localhost/YueJian/public/admin/json/anQuestion?masterquestion_id=15&content=%22%E5%BE%88%E5%A5%BD%22;*/

    /*获取用户自己问题接口*/
    public function userQuestion () {
        $user_id = input('user_id');
        $sql = Db::table('masterquestion')
            ->where('user_id',$user_id)
            ->select();
        return json_encode($sql);
    }
    /*http://localhost/YueJian/public/admin/json/userquestion?user_id=5*/

    /*获取大师自己的问题接口*/
    public function masterQuestion () {
        $master_id = input('master_id');
        $sql = Db::table('masterquestion')
            ->where('master_id',$master_id)
            ->select();
        return json_encode($sql);
    }
    /*http://localhost/YueJian/public/admin/json/masterquestion?master_id=1*/

    /*获取当前俱乐部课程信息*/
    public function getCourse()
    {
        $parm=input('cub_id');
        $sql=Db::table('course')
            ->alias('a')
            ->join('cub c','c.cub_id = a.cub_id')
            ->where('a.cub_id',$parm)
            ->find();
        return json_encode($sql);
    }
    /*http://localhost/YueJian/public/admin/json/getCourse?cub_id=11*/

    public function getVideo()
    {
        $parm=input('cub_id');
        $sql=Db::table('video')
            ->alias('a')
            ->join('cub c','c.cub_id = a.cub_id')
            ->where('a.cub_id',$parm)
            ->find();
        return json_encode($sql);
    }
    /*http://localhost/YueJian/public/admin/json/getVideo?cub_id=11;*/



    //624接口*******************************************************

    public function cublist()//获取俱乐部列表
    {
        $select=Db::table('cub')->select();
        return json_encode($select);
    }

    public function delAttention () {
        $master=input('master_id');
        $user = input('user_id');
        $sql=Db::table('attention')
            ->where('master_id',$master)
            ->where('user_id',$user)
            ->delete();
        if($sql == 0) {
            return "取消成功";
        }else {
            return "失败";
        }
    }
    //访问接口http://localhost/YueJian/public/admin/json/delAttention?master_id=2
    
    public function addUser () {
        $un=input();
        $data = [
            'user_name' => $un['username_'],
            'user_password' => $un['password_']
        ];
        // dump($data);
        $sql = Db::table('users')
        ->insert($data);
        if($sql) {
            return 'success';
        }
    }

    
   // http://localhost/YueJian/public/index.php/admin/json/masterquestionfind?masterquestion_id=1
    //621 接口 ***********************************************

    public function addComment () {//http://localhost/YueJian/public/admin/json/addcomment?publish_id=1&user_id=1&comment_content=hhh
        // dump('a');
        $temp = input();
        $sql=Db::table('publish')
            ->where('publish_id',$temp['publish_id'])
            ->find();
        $sql1=Db::table('users')
            ->where('user_id',$temp['user_id'])
            ->find();
        if($sql && $sql1) {
              $data = [
            'publish_id' => $temp['publish_id'],
            'user_id' => $temp['user_id'],
            'comment_content' => $temp['comment_content']
            ];
            // dump($data);

            $sql3 = Db::table('comment')
            ->insert($data);

            if($sql3) {
                return 'success';
            }
        }
    }

    public function addPublish(){
        $uid=input('param.uid');
        $pname=input('param.pname');
        $file= request()->file('ppic');
        $time=date('y-m-d h:i:s',time());
        if($uid&&$pname&&$file){
                $sql=['user_id'=>$uid,'publish_name'=>$pname,'publish_onloadtime'=>$time];
                if ($file){
                    $posterinfo = $file->validate(['size' => 10 * 1024 * 1024, 'ext' => 'jpg,png'])->move(ROOT_PATH . 'public' . DS . 'static');
                    $postername = $posterinfo->getFilename();
                    $sql['publish_pic']=$postername;
                }
                $result=db('publish')->insert($sql);
                if ($result){
                    $json['success']='1';
                    return json_encode($json);
                }
                else{
                    $json['success']='0';
                    return json_encode($json);
                }

        }
        else{
            $json['success']='0';
            return json_encode($json);
        }
    }

    //622 接口**********************************************
    public function activitylist(){//获取精彩活动列表接口
    	$select=Db::table('activity')->select();
    	return json_encode($select);
    }

    public function activityfind(){//获取当前精彩活动信息接口
     	$id=input('activity_id');
    	$select=Db::table('activity')->where('activity_id',$id)->find();
    	return json_encode($select);
    }

    public function masterlist(){//获取权威大师列表接口
    	$select=Db::table('master')->select();
    	return json_encode($select);
    }

    public function masterfind(){//获取当前权威大师信息接口
    	$id=input('master_id');
    	$select=Db::table('master')->where('master_id',$id)->find();
    	return json_encode($select);
    }

    public function gamelist(){//获取最近比赛列表接口
    	$select=Db::table('game')->select();
    	return json_encode($select);
    }

    public function gamefind(){//获取当前比赛信息接口
    	$id=input('game_id');
    	$select=Db::table('game')->where('game_id',$id)->find();
    	return json_encode($select);
    }

   public function mastervideolist(){//获取相关视频列表接口
        $v=Db::table('mastervideo')
            ->alias('v')
            ->join('master t','v.master_id = t.master_id')
            ->select();
             $t=Db::table('master')
             ->select();
        return json_encode($v);
    }
    //http://localhost/YueJian/public/index.php/admin/json/mastervideolist

    public function mastervideofind(){//获取当前比赛信息接口
        $id=input('mastervideo_id');
        $v=Db::table('mastervideo')
            ->alias('v')
            ->join('master t','v.master_id = t.master_id')
            ->where('mastervideo_id',$id)
            ->find();
        return json_encode($v);
    }

}
